import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ImgUtils {
    // 图像处理 把脸框出来
    public static void draw(String input, String output, List<Map<String,Double>> posList) throws IOException {
//        BufferedImage image = ImageIO.read(new File("d:\\test3.jpg"));
        BufferedImage image = ImageIO.read(new File(input));
        Graphics g = image.getGraphics();
        g.setColor(Color.RED);//画笔颜色
        for (Map<String, Double> map : posList) {
            int l = map.get("left").intValue();
            int r = map.get("right").intValue();
            int b = map.get("bottom").intValue();
            int t = map.get("top").intValue();
            g.drawLine(l,t,r,t);
            g.drawLine(l,b,r,b);
            g.drawLine(l,t,l,b);
            g.drawLine(r,t,r,b);
        }
//        g.drawRect(0, 0, r-l, b-t);//矩形框(原点x坐标，原点y坐标，矩形的长，矩形的宽)
        //g.dispose();
//        FileOutputStream out = new FileOutputStream("d:\\test4.jpg");//输出图片的地址
        FileOutputStream out = new FileOutputStream(output);//输出图片的地址
        ImageIO.write(image, "png", out);
        System.out.println("drew over");
    }

//    public static void main(String[] args) throws IOException {
//        draw("src\\main\\resources\\img\\1.png",
//                "src\\main\\resources\\img\\res\\1.png",
//                233.6475830078125,
//                272.310791015625,
//                202.7095947265625,
//                156.3901824951172);
//    }
}
